Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid duplicated evaluation in ProgramMemoryState::removeModifiedVars() #6628

Merged
merged 1 commit into from
Jul 26, 2024

Conversation

firewave
Copy link
Collaborator

No description provided.

@firewave
Copy link
Collaborator Author

firewave commented Jul 21, 2024

-D __GNUC__ --check-level=exhaustive lib/utils.cpp

Clang 18 999,900,672 -> 874,701,202
GCC 14 1,026,753,345 -> 892,531,811

@pfultz2 please have a look

@firewave firewave marked this pull request as draft July 21, 2024 18:58
@firewave firewave marked this pull request as ready for review July 21, 2024 19:12
@firewave firewave changed the title programmemory.cpp: avoid duplicated evaluation in ProgramMemoryState::removeModifiedVars() avoid duplicated evaluation in ProgramMemoryState::removeModifiedVars() Jul 21, 2024
@firewave
Copy link
Collaborator Author

firewave commented Jul 21, 2024

This should help with https://trac.cppcheck.net/ticket/12271.

@chrchr-github
Copy link
Collaborator

Looks like this (anti-) pattern also exists in fillProgramMemoryFromAssignments() and valueflow.cpp::evaluateInt()

@firewave
Copy link
Collaborator Author

Looks like this (anti-) pattern also exists in fillProgramMemoryFromAssignments() and valueflow.cpp::evaluateInt()

Yes, I did not touch those because they are not in the hot path. Well one of them shows up in the profiler but changing it let to strange results with one of the compilers so I left it for now.

{
if (!condition)
return false;
MathLib::bigint result = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be on the safe side, we should initialize result before the first return.

return {1};
if (result == 0)
return {0};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to just call execute and use the isTrue and isFalse functions:

auto result = execute(cond, pm, *settings);
if(isTrue(result))
    return {1};
if(isFalse(result))
    return {0};
return {};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then there is no need to refactor the evaluateCondition function.

Copy link
Contributor

@pfultz2 pfultz2 Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this same code could be used in evaluateInt as well, we just need to expose the isTrue and isFalse functions.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. As mentioned before I will not touch other code until I encounter it in a profile.

@firewave firewave merged commit 8368943 into danmar:main Jul 26, 2024
63 checks passed
@firewave firewave deleted the pm-cond branch July 26, 2024 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants